﻿using Ease.EaseMission.Runtime;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace Ease.EaseMission.Editor
{
    public static class MissionMenu
    {
        [MenuItem("Tools/MissionEW")]
        public static void ShowExample()
        {
            MissionEW wnd = EditorWindow.GetWindow<MissionEW>();
            wnd.titleContent = new GUIContent("MissionEW");
        }

        [OnOpenAsset(1)]
        private static bool DoubleClickToOpenWindow(int instanceID, int line)
        {
            
            var obj = EditorUtility.InstanceIDToObject(instanceID);
            string path = AssetDatabase.GetAssetPath(obj);
            if (obj is MissionDataSo)
            {
                DialogEW[] windows = Resources.FindObjectsOfTypeAll<DialogEW>();
                if (windows.Length > 0)
                {
                    Debug.LogError("窗口已经打开");
                    return false;
                }

                ShowExample();
                return true;
            }

            return false;
        }
    }
}